/**
 *project huodong
 *com.yysoft.web.base.BaseAction.java 
 *copyrite@ by admin@xkshow.cn
 ****************************************************************
 *         VERSION       DATE            BY       CHANGE/COMMENT
 * --------------------------------------------------------------
 *          1.0          2012-6-10     hardy         create
 ****************************************************************
 *note:
 ***************************************************************/ 
package com.yysoft.web.base;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.apache.struts2.util.ServletContextAware;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport implements SessionAware,ServletContextAware, ServletRequestAware, ServletResponseAware {
	protected final Log logger = LogFactory.getLog(getClass());
	
	private Map session = new HashMap();
	protected HttpServletRequest request;
	protected ServletContext servletContext;
	protected HttpServletResponse response;
	private String action = "index" ;
	//page
	private int page = 1;
	private long total;
	
	protected String executeMethod(String method) throws Exception {
		String result = "";
		try {
			Class[] c = null;
			Method m = this.getClass().getMethod(method, c);
			Object[] o = null;
			result = (String) m.invoke(this, o);
			logger.debug("*******baseAction executeMethod result:**********"+result);			
		} catch (Exception e) {
			e.printStackTrace();;
		}finally{
			return result;
		}
	}
	public Object getBean(String name){
        javax.servlet.ServletContext context = this.getServletContext();
        ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
        return ctx.getBean(name);
	}
	public Map getSession() {
		return session;
	}

	public void setSession(Map session) {
		this.session = session;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}
	
	public void setServletRequest(HttpServletRequest request){
	    this.request = request;
	  }

	public ServletContext getServletContext() {
		return servletContext;
	}

	public void setServletContext(ServletContext servletContext) {
		this.servletContext = servletContext;
	}

	public HttpServletResponse getResponse() {
		return response;
	}

	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}
	
	public void setServletResponse(HttpServletResponse response){
	    this.response = response;
    }
	
	
	
}
